package io.gitee.zhucan123.core.infrastructure.exception.advice;

import com.niimbot.middlend.core.infrastructure.exception.EntityExistsException;
import com.niimbot.middlend.core.infrastructure.exception.OrderLockedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @author: jiwangc
 * @date: 2019/10/18 9:55
 */
@RestControllerAdvice
@Slf4j
public class OrderLockedExceptionAdvice {

  @ExceptionHandler(OrderLockedException.class)
  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  public ErrorDTO handleBindException(HttpServletRequest req, EntityExistsException ex) {
    String errorMessage = ex.getMessage();
    String errorURL = req.getRequestURL().toString();
    return new ErrorDTO(errorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value(), errorURL);
  }
}
